<template>
  <div>
    <div class="search">
      <el-form :inline="true" :model="queryParams" size="small">
        <el-form-item label="部门">
          <depart-tree
            style="width: 200px"
            class="depart-tree"
            v-model="queryParams.deptNo"
            :departments="departments"
          />
        </el-form-item>
        <el-form-item label="姓名">
          <el-input v-model="queryParams.userName" size="small"/>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSearch">查 询</el-button>
        </el-form-item>
      </el-form>
    </div>
      <acc-table height='400px' :tableData="tableData" :columnDefs="columnDefs">
        <template #order={index}>
          <span>{{index | orderIndex(pageVo)}}</span>
        </template>
        <template #idCardNo={row}>
          <span>{{isShow && row.idCardNo.length === 18 ? $options.filters.idCarDesensitization(row.idCardNo) :  row.idCardNo}}</span>
        </template>
        <template #telephoneNo={row}>
          {{isShow ? $options.filters.cellularPhone(row.telephoneNo) : row.telephoneNo}}
        </template>
        <template #action={row}>
          <el-button type="text" size="mini" @click="handleRemove(row)">移除</el-button>
        </template>
      </acc-table>
      <acc-page :total='total' :page-size='pageVo.pageSize' :current-page='pageVo.pageNum'  @current-change='handleChangePage' @size-change='handleChangeSize'></acc-page>
  </div>
</template>

<script>
import { decrypt } from '@/utils/crypto'
import { columnDefs } from './mock'
import { queryDeptListBySchoolNo } from '@/views/children/basic/js/teacherInfo'
import { queryWhiteListByPage, deleteWhiteList } from '@/views/children/antiepidemic/js/preventionRiskScreen'
import DepartTree from '@/views/children/basic/components/departTree'
export default {
  components: { DepartTree },
  props: {
    currentCampus: String,
    updatedTime: String,
    isShow: Boolean
  },
  data () {
    return {
      departments: [],
      queryParams: {
        deptNo: null,
        userName: null
      },
      columnDefs: [],
      tableData: [],
      pageVo: {
        pageNum: 1,
        pageSize: 10
      },
      total: 0,
      gradeOptions: [],
      classOptions: [],
      currentHeaderSelect: []
    }
  },
  created () {
    this.columnDefs = columnDefs
    this.queryDeptListBySchoolNo()
    this.handleSearch()
  },
  methods: {
    queryDeptListBySchoolNo () {
      queryDeptListBySchoolNo({}).then(res => {
        if (res.code === 0) {
          this.departments = res.data
        }
      })
    },
    handleSearch () {
      this.pageVo.pageNum = 1
      this.loadDataList()
    },
    loadDataList () {
      queryWhiteListByPage(this.formData()).then(res => {
        res.data = JSON.parse(decrypt(res.data))
        this.tableData = res.data.records
        this.total = res.data.total
      })
    },
    handleChangePage (page) {
      this.pageVo.pageNum = page
      this.loadDataList()
    },
    handleChangeSize (size) {
      this.pageVo.pageSize = size
      this.handleSearch()
    },
    handleClickHeaderSelect (val) {
      this.currentHeaderSelect = val
      this.handleSearch()
    },
    formData () {
      let temp = {}
      Object.assign(temp, this.queryParams, this.pageVo)
      // let userInfo = localStorage.getItem('Standard__User-Info')
      // temp.tenantNo = JSON.parse(userInfo).value.tenantNo
      temp.userType = 1
      return temp
    },
    handleRemove (row) {
      this.$confirm('是否移除白名单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        deleteWhiteList(row.id).then(() => {
          this.$message.success('移除白名单成功')
          this.loadDataList()
        })
      }).catch(() => {})
    }
  }
}
</script>

<style lang='scss' scoped>
.search {
  display: flex;
  justify-content: space-between;
}
</style>
